package gl.android.biyiqing.competent;

import gl.adapter.SimpleAdapter.OnItemChildViewClick;
import gl.android.biyiqing.LoveAskDetailActivity;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.huewu.pla.lib.internal.PLA_AdapterView;

public class OnLoveAskItemClickListener implements OnItemClickListener,
		com.huewu.pla.lib.internal.PLA_AdapterView.OnItemClickListener, OnItemChildViewClick {
	public final static String KEY_ASK_ID = "askid";
	private Context mContext;
	private String jsonArrayData;

	public OnLoveAskItemClickListener(Context mContext, String jsonArrayData) {
		this.mContext = mContext;
		this.jsonArrayData = jsonArrayData;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		goUserInfoActivity(arg2);
	}

	private void goUserInfoActivity(int arg2) {
		Intent intent = new Intent(mContext, LoveAskDetailActivity.class);
		Type stringStringMap = new TypeToken<ArrayList<Map<String, String>>>() {
		}.getType();
		List<Map<String, String>> map = new Gson().fromJson(jsonArrayData,
				stringStringMap);
		intent.putExtra(KEY_ASK_ID, map.get(arg2).get(KEY_ASK_ID));
		mContext.startActivity(intent);
	}

	@Override
	public void onItemClick(PLA_AdapterView<?> parent, View view, int position,
			long id) {
		goUserInfoActivity(position);
	}

	@Override
	public void onClick(View view, int position) {
		goUserInfoActivity(position);
		
	}

}
